/* GUI CONVERTED from rcrsfca.p (converter v1.75) Mon Nov 13 06:36:18 2000 */
/* rcrsfca.p - Release Management Customer Schedules                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/* REVISION: 7.3    LAST MODIFIED: 12/08/92           BY: WUG *G462*    */
/* REVISION: 7.3    LAST MODIFIED: 01/11/95           BY: WUG *G0C3*    */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98    BY: *K1Q4* Alfred Tan    */
/* REVISION: 8.6E   LAST MODIFIED: 07/10/98    BY: *H1LW* Surekha Joshi */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00    BY: *N0KP* Mark Brown    */
/* REVISION: 9.1    LAST MODIFIED: 10/09/00    BY: *N0R9* Jean Miller   */
/* REVISION: 9.1    LAST MODIFIED: 11/08/00    BY: *N0TN* Jean Miller   */

/* UPDATE FORECAST SUBPROGRAM */

         {mfdeclre.i}
/*N0R9*/ {gplabel.i}

/* ******* Begin Translatable Strings Definitions ******** */

/*H1LW*/
/*N0R9* &SCOPED-DEFINE rcrsfca_p_1 "Sales" */
/* MaxLen: Comment: */

/* ****** End Translatable Strings Definitions ******** */


         /*G0C3 MODIFIED FOLLOWING PARAMETER LIST*/
         define input parameter order_nbr like sod_nbr.
         define input parameter order_line like sod_line.
         define input parameter prev_qty_ord as decimal.
         define input parameter qty_ord as decimal.
         define input parameter due_dt as date.
         define input parameter due_time as character.
         define input parameter reference as character.

         define new shared variable part as character.
         define new shared variable eff_date as date.
         define new shared variable qty like sod_qty_ord.

         define variable week as integer.
         define variable fcs_recid as recid.
         define variable i as integer.
         define variable mrpref as character.

/*G0C3*/ find sod_det where sod_nbr = order_nbr and sod_line = order_line
/*G0C3*/ no-lock.

         if prev_qty_ord <> 0 and prev_qty_ord <> qty_ord
         then do:
            {fcsdate2.i due_dt week}
            if week = 0 then
               find fcs_sum where fcs_part = sod_part
                and fcs_site = sod_site
                and fcs_year = year(due_dt) - 1 use-index fcs_partyear no-error.
            else if week = 53 then
               find fcs_sum where fcs_part = sod_part
                and fcs_site = sod_site
                and fcs_year = year(due_dt) + 1 use-index fcs_partyear no-error.
            else
               find fcs_sum where fcs_part = sod_part
                and fcs_site = sod_site
                and fcs_year = year(due_dt) use-index fcs_partyear no-error.

            if not available fcs_sum
            and can-find (pt_mstr where pt_part = sod_part) then do:
               create fcs_sum.
               assign
                  fcs_part = sod_part
                  fcs_site = sod_site.
               if week = 0 then
                  fcs_year = year(due_dt) - 1.
               else if week = 53 then
                  fcs_year = year(due_dt) + 1.
               else
                  fcs_year = year(due_dt).
            end.

            if available(fcs_sum) then do:

               if week = 53 then
                  week = 1.
               if week = 0 then
                  week = 52.

               fcs_recid = recid(fcs_sum).

               if sod_consume = no then
                  fcs_abnormal[week] = fcs_abnormal[week] - prev_qty_ord.
               else do:
                  fcs_sold_qty[week] = fcs_sold_qty[week] - prev_qty_ord.
               end.

            end.

         end.

         if can-find (pt_mstr where pt_part = sod_part) then do:

            if qty_ord <> 0 and due_dt <> ?
            and (prev_qty_ord <> qty_ord)
            then do:
               {fcsdate2.i due_dt week}
               if week = 0 then
                  find fcs_sum where fcs_part = sod_part
                   and fcs_site = sod_site
                   and fcs_year = year(due_dt) - 1
                  use-index fcs_partyear no-error.
               else if week = 53 then
                  find fcs_sum where fcs_part = sod_part
                   and fcs_site = sod_site
                   and fcs_year = year(due_dt) + 1
                  use-index fcs_partyear no-error.
               else
                  find fcs_sum where fcs_part = sod_part
                   and fcs_site = sod_site
                   and fcs_year = year(due_dt) use-index fcs_partyear no-error.

               if not available fcs_sum then do:
                  create fcs_sum.
                  assign
                     fcs_part = sod_part
                     fcs_site = sod_site.
                  if week = 0 then
                     fcs_year = year(due_dt) - 1.
                  else if week = 53 then
                     fcs_year = year(due_dt) + 1.
                  else
                     fcs_year = year(due_dt).
               end.

               if available(fcs_sum) then do:

                  if week = 53 then week = 1.
                  if week = 0 then week = 52.

                  fcs_recid = recid(fcs_sum).

                  if sod_consume = no then
                     fcs_abnormal[week] = fcs_abnormal[week] + qty_ord.
                  else do:
                     fcs_sold_qty[week] = fcs_sold_qty[week] + qty_ord.
                  end.

               end.

            end.

         end. /* if can-find(pt_mstr) */

/*G0C3 ADDED FOLLOWING SECTION*/

         /*UPDATE PLANNING FORECAST RECORD*/
         mrpref = string(order_line,"9999")
                  + string(year(due_dt),"9999")
                  + string(month(due_dt),"99")
                  + string(day(due_dt),"99")
                  + due_time
                  + reference.

         for each mrp_det exclusive-lock
         where mrp_dataset = "pb_sold"
         and mrp_nbr = order_nbr
         and mrp_line = mrpref:
/*GUI*/ if global-beam-me-up then undo, leave.


            {fcsdate2.i mrp_due_date week}

            if week = 0 then
               find fcs_sum where
                    fcs_part = mrp_part
                and fcs_site = mrp_site
                and fcs_year = year(mrp_due_date) - 1
               use-index fcs_partyear no-error.
            else if week = 53 then
               find fcs_sum where
                    fcs_part = mrp_part
                and fcs_site = mrp_site
                and fcs_year = year(mrp_due_date) + 1
               use-index fcs_partyear no-error.
            else
               find fcs_sum where fcs_part = mrp_part
                and fcs_site = mrp_site
                and fcs_year = year(mrp_due_date)
               use-index fcs_partyear no-error.

            if not available fcs_sum then
            if mrp_qty <> 0 then do:
               create fcs_sum.
               assign
                  fcs_part = mrp_part
                  fcs_site = mrp_site.

               if week = 0 then
                  fcs_year = year(mrp_due_date) - 1.
               else if week = 53 then
                  fcs_year = year(mrp_due_date) + 1.
               else
                  fcs_year = year(mrp_due_date).
            end.

            qty = mrp_qty.

            if available fcs_sum then do:

               if week = 53 then week = 1.
               if week = 0 then week = 52.

               fcs_recid = recid(fcs_sum).

               if sod_consume = no then
                  fcs_abnormal[week] = fcs_abnormal[week] - qty.
               else
                  fcs_sold_qty[week] = fcs_sold_qty[week] - qty.

               {inmrp.i &part=mrp_det.mrp_part &site=mrp_det.mrp_site}

               delete mrp_det.

            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         {mfdel.i pk_det "where pk_user = mfguser"}

         assign
            part = sod_part
            eff_date = due_dt
            qty = 1.

         {gprun.i ""sopbex.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         for each pk_det where pk_user = mfguser
         and pk_qty <> 0:
/*GUI*/ if global-beam-me-up then undo, leave.


            {fcsdate2.i pk_start week}

            if week = 0 then
               find fcs_sum where
                    fcs_part = pk_part
                and fcs_site = sod_site
                and fcs_year = year(pk_start) - 1
               use-index fcs_partyear no-error.
            else if week = 53 then
               find fcs_sum where
                    fcs_part = pk_part
                and fcs_site = sod_site
                and fcs_year = year(pk_start) + 1
               use-index fcs_partyear no-error.
            else
               find fcs_sum where
                    fcs_part = pk_part
                and fcs_site = sod_site
                and fcs_year = year(pk_start)
               use-index fcs_partyear no-error.

            if not available fcs_sum then
            if pk_qty <> 0 then do:

               create fcs_sum.
               assign
                  fcs_part = pk_part
                  fcs_site = sod_site.

               if week = 0 then
                  fcs_year = year(pk_start) - 1.
               else if week = 53 then
                  fcs_year = year(pk_start) + 1.
               else
                  fcs_year = year(pk_start).

            end.

            qty = pk_qty * qty_ord.

            if available fcs_sum then do:

               if week = 53 then week = 1.
               if week = 0 then week = 52.

               fcs_recid = recid(fcs_sum).

               if sod_consume = no then
                  fcs_abnormal[week] = fcs_abnormal[week] + qty.
               else
                  fcs_sold_qty[week] = fcs_sold_qty[week] + qty.
            end.


/*H1LW*/    /* TENTH PARAMETER CHANGED FROM "SALES" TO "Sales"        */
/*H1LW*/    /* TO FOLLOW TRANSLATION STANDARDS                        */
/*N0TN*/    /* Changed pre-processor to Term */
            {mfmrw.i "pb_sold" pk_part sod_nbr mrpref """" ?
             due_dt "qty" "DEMAND" SALES sod_site}

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


/*G0C3 END SECTION*/
